﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace InteractiveKidsShow
{
    class SpeechDecisionPart : StoryPart
    {
        public int vidLength;
        public string wordDesired;
        public bool wordWasSaid; // change this when "word said" event interrupts us
        public Uri vidIfDone;
        public Uri vidIfNotDone;
        public bool hasVidPlayed;
        public bool hasSecondVidPlayed;

        public SpeechDecisionPart(Uri requestVid, int requestVidLength, string word, Uri done, Uri not)
        {
            vid = requestVid;
            vidLength = requestVidLength;
            wordDesired = word;
            vidIfDone = done;
            vidIfNotDone = not;
            hasVidPlayed = false;
            wordWasSaid = false;
        }


        public void Play(ref MediaElement mediaPlayer, ref Speech speechObject)
        {
            if (!hasVidPlayed) // if the first vid (request) hasn't played, play that
            {
                mediaPlayer.Source = vid;
                mediaPlayer.Play();
                hasVidPlayed = true;
                speechObject.requestSpeech(wordDesired, vidLength);
            }
            else if (wordWasSaid) // else if it has and they said the right word
            {
                hasSecondVidPlayed = true;
                mediaPlayer.Source = vidIfDone;
                mediaPlayer.Play();
            }
            else // otherwise it has but they didn't say the right word
            {
                    hasSecondVidPlayed = true;
                    mediaPlayer.Source = vidIfNotDone;
                    mediaPlayer.Play();
            }
        }
    }
}
